package com.xinsmartsky.penmaji.penmaji;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by wangxiao on 16-1-11.
 */
public class PrintMainActivity extends Activity implements View.OnClickListener {
    private LinearLayout advance_lin_02;
    private LinearLayout advance_lin_03;
    private int devfd = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_print_main);
        devfd = getIntent().getIntExtra("fd", 0);
        Log.i("fd", "print===" + devfd);
        findViewById();
        setOnClickListener();
        initView();
    }

    private void findViewById() {
        advance_lin_02 = (LinearLayout) findViewById(R.id.advance_lin_02);
        advance_lin_03 = (LinearLayout) findViewById(R.id.advance_lin_03);
    }

    private void setOnClickListener() {

    }

    private void initView() {
        for (int i = 0; i < 4; i++) {
            Log.i("aaaaa ", "i =" + i);
            advance_lin_02.addView(addView(i));
            advance_lin_03.addView(addView(i + 4));
        }
    }

    private View addView(int text) {
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
        lp.setMargins(4, 0, 4, 0);
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.activity_print_mainitem, null);
        ImageView printmi_iv_dec = (ImageView) view.findViewById(R.id.printmi_iv_dec);
        ImageView printmi_iv_rai = (ImageView) view.findViewById(R.id.printmi_iv_rai);
        TextView printmi_tv_title = (TextView) view.findViewById(R.id.printmi_tv_title);
        switch (text) {
            case 0: {
                printmi_tv_title.setText("信息间距");
                break;
            }
            case 1: {
                printmi_tv_title.setText("英文宽度");
                break;
            }
            case 2: {
                printmi_tv_title.setText("英文高度");
                break;
            }
            case 3: {
                printmi_tv_title.setText("字符间隔");
                break;
            }
            case 4: {
                printmi_tv_title.setText("喷印速度");
                break;
            }
            case 5: {
                printmi_tv_title.setText("中文宽度");
                break;
            }
            case 6: {
                printmi_tv_title.setText("中文高度");
                break;
            }
            case 7: {
                printmi_tv_title.setText("中文间隔");
                break;
            }
        }
        printmi_iv_dec.setOnClickListener(PrintMainActivity.this);
        printmi_iv_rai.setOnClickListener(PrintMainActivity.this);
        view.setLayoutParams(lp);
        return view;
    }

    @Override
    public void onClick(View v) {
        TextView textset = (TextView) v.findViewById(R.id.printmi_tv_title);
        int tvnum = Integer.valueOf(textset.getText().toString());
        switch (v.getId()) {
            case R.id.printmi_iv_dec: {
                if (tvnum > 0 && tvnum < 11) {
                    tvnum--;
                    textset.setText("0" + tvnum);
                } else if (tvnum > 10) {
                    tvnum--;
                    textset.setText("" + tvnum);
                }
                break;
            }
            case R.id.printmi_iv_rai: {
                if (tvnum < 100) {
                    tvnum++;
                    textset.setText("" + tvnum);
                }
                break;
            }
        }
    }
}
